//
//  HJCPopoverPresentationController.swift
//  新浪微博Swift
//
//  Created by 郝俊聪 on 15/5/14.
//  Copyright (c) 2015年 heima. All rights reserved.
//

import UIKit

class HJCPopoverPresentationController: UIPresentationController {
    
    
    
    /// 展现视图的大小
    var presentedFrame: CGRect = CGRectZero
    
    
    //增加遮罩层
    lazy var dummyView : UIView = {
        let dummyView = UIView()
        dummyView.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        //增加手势
        let tap = UITapGestureRecognizer(target: self, action: "touchDummyView")
        dummyView.addGestureRecognizer(tap)
        
        return dummyView
    }()
    
    //手势执行的方法
    func touchDummyView(){
        //让演示控制器退出
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
    
    
    
    //设置容器控制器
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        //设置遮罩的大小
        dummyView.frame = containerView.bounds
        
        //添加遮罩到容器
        containerView.insertSubview(dummyView, atIndex: 0)
        
        
        //设置演示视图的大小
        presentedView().frame =  presentedFrame
        
    }
   
}
